package com.block.job.service;

import com.block.common.constant.RedisKeyConstant;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class DeleteOptimalProductJob {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    //@XxlJob("DeleteOptimalProductJob")
    public void delete() throws Exception {
        XxlJobHelper.log("重置前一天用户匹配产品所有数据---------开始执行--------");

        Set<String> keys = stringRedisTemplate.keys(RedisKeyConstant.PRODUCT_USER_ID + "*");

        if (keys != null && !keys.isEmpty()) {
            // 删除所有匹配的 Key
            stringRedisTemplate.delete(keys);
            System.out.println("已删除以下 Redis Key：" + keys);
        } else {
            System.out.println("没有找到需要删除的 Redis Key");
        }
    }
}
